package com.eve.microworld.common.tools;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**时间获取工具
 * 
 * @author Norsie
 * @create 12-12-26
 */
public class ComTimeTools
{

    /** 按照给定格式返回日期时间
     * 
     * @param format
     *      yyyy年
     *      MM月
     *      dd日
     *      HH时
     *      mm分
     *      ss秒
     * @return
     */
    public static String getTime(String format) {
        DateFormat mFormat = new SimpleDateFormat (format);
        Date   curDate   =   new   Date(System.currentTimeMillis());
        return mFormat.format(curDate);
    }
    
    /**计算时间差(Format:yyyy-MM-dd HH:mm:ss)
     * 
     * @param earlyTime yyyy-MM-dd HH:mm:ss
     * @param curTime yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static String getTimeDiff(String earlyTime,String curTime) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try
        {
        Date mEarlyTime=df.parse(earlyTime);
        Date mCurTime=df.parse(curTime);
        long diff =mCurTime.getTime()-mEarlyTime.getTime();
        long days = diff / (1000 * 60 * 60 * 24);
        return days+"";
        }
        catch (Exception e)
        {
            LogTools.error("ComTimeTools Error:getTimeDiff", e);
            return "";
        }
        
    }
    
}
